//样式判断
if(document.body.clientHeight<600){
	// $(".AreYouSure section").height("calc(100% + 2.39rem)")
}
$(function(){
	$(".choose>ul>li").eq(0).trigger("click");
	$(".choose>ol>li").eq(0).trigger("click").addClass("active");
})
$(".choose>ul>li").eq(0).on("click",function(){
	type=2
	$(".active").css({"background":"url('../../img/personalImg/green.png') no-repeat","backgroundSize":"100% 100%","color":"white"})
	$(this).css({"background":"url('../../img/personalImg/wei.png') no-repeat","backgroundSize":"100% 100%"});
	$(this).siblings().css({"background":"url('../../img/images/baoIcon.png') no-repeat","backgroundSize":"100% 100%"});
	$(".choose>ol>li").on("click",function(){
		money=parseInt($(this).html())
		if(userMoney<money){
			$(".push").attr("check","false")
			pushCss()
		}else{
			$(".push").attr("check","true")
			pushCss()
		}
		$(".choose>ol>li").removeClass("active").css({"background":"#F0F0F0","color":"#666"})
		$(this).addClass("active").css({"background":"url('../../img/images/green.png') no-repeat","backgroundSize":"100% 100%","color":"white"})
	})
})
$(".choose>ul>li").eq(1).on("click",function(){
	type=1
	$(".active").css({"background":"url('../../img/images/blue.png') no-repeat","backgroundSize":"100% 100%","color":"white"})
	$(this).css({"background":"url('../../img/personalImg/bao.png') no-repeat","backgroundSize":"100% 100%"});
	$(this).siblings().css({"background":"url('../../img/images/weiIcon.png') no-repeat","backgroundSize":"100% 100%"});
	$(".choose>ol>li").on("click",function(){
		$(".choose>ol>li").removeClass("active").css({"background":"#F0F0F0","color":"#666"})
		$(this).addClass("active").css({"background":"url('../../../img/personalImg/blue.png') no-repeat","backgroundSize":"100% 100%","color":"white"})
	})
})


$(".choose>ol>li").on("click",function(){
		money=parseInt($(this).html())
		if(userMoney<money){
			$(".push").attr("check","false")
			pushCss()
		}else{
			$(".push").attr("check","true")
			pushCss()
		}
		$(".choose>ol>li").removeClass("active").css({"background":"#F0F0F0","color":"#666"})
		$(this).addClass("active").css({"background":"url('../../img/personalImg/green.png') no-repeat","backgroundSize":"100% 100%","color":"white"})
})



var type=2,money=0,userMoney=localStorage.balance;
console.log(userMoney)
if(parseInt(userMoney)<10){
	$(".push").attr("check","false");
	pushCss();
}else{
	$(".push").attr("check","true");
	pushCss();
}

$(".choose").find("i").html(userMoney);
//function show(){
//	if(true){
//		$(".nullAct").css("display","none");
//		$.ajax({
//			type:"POST",
//			async:true,
//			url:"120.76.201.26:8088/bill/withdraw_cash_new",
//			beforeSend: function(request) {
//		        request.setRequestHeader("Authorization","Basic"+token);
//		    },
//			success:function(e){
//				console.log(e.data.current_balance)
//				userMoney=parseInt(e.data.current_balance);
//				if(parseInt(e.data.current_balance)<10){
//					$(".push").attr("check","false");
//					pushCss();
//		    	}else{
//		    		$(".push").attr("check","true");
//					pushCss();
//		    	}
//				$(".choose").find("i").html(e.data.current_balance)
//			
//			},error:function(a){
//				
//			}
//			})
//	}else{
//		$(".nullAct").css("display","block");
//	}
//}

//去提交
function pushCss(){
	if($(".push").attr("check")=="false"){
		$(".push").css("background","#959595").html("可提现余额不足")
	}else{
		$(".push").css("background","#FF6B60").html("提交申请")
	}
}
$(".push").on("click",function(){
	//微信公众号提现原版
	if($(".push").attr("check")=="true"){
		console.log($(".choose").eq(0).find("li.active").index())
		if($(".choose").eq(0).find("li.active").length){
			//提现的金额
			console.log(parseInt($(".choose").eq(0).find("li.active").html()))
			console.log(money)
			$(".AreYouSure").fadeIn()
		}else{
			$(".bindPhoneEmail").find("h2").text("请选择提现金额！")
			$(".bindPhoneEmail").fadeIn(function(){

			})
		}
	}	
})
//是否确认兑换红包
$(".closeSure").on("click",function(){
	$(".AreYouSure").fadeOut()
})
var getkeys=true;
$(".sureSure").on("click",function(){
	$(".AreYouSure>div").fadeOut(function(){
		//调用生成兑换码的接口
		getKey();
	})
})
console.log(localStorage.logintoken)
//获取兑换码的接口函数
function getKey(){
	if(getkeys){
		$.ajax({
		url:"http://120.76.201.26:8088/bill/withdraw_cash",
		type:"POST",
		data:{
			money:money
		},
		beforeSend: function(request) {
	        request.setRequestHeader("Authorization","Basic"+localStorage.logintoken);
	    },
		success:function(e){
			getkeys=false;
			console.log(e)
			if(e.code==0){
				$(".AreYouSure").find("section").css("left","0")
				$(".copyT").val(e.data.convert_code)
				//给通知刷新个人中心
				localStorage.balance=localStorage.balance-money
				$(".explain").find("input").val("")
			}else{
				console.log("用户未登录或登录超时")
			}
			setTimeout(function(){
				getkeys=true;
			},2000)
		},
		error:function(){
			// $(".bindPhone").fadeIn();
			console.log("请求失败")
			$(".FalseMess>div").html("服务器错误，请稍后重试");
			$(".FalseMess").fadeIn();
			setTimeout(function(){
				$(".FalseMess").fadeOut();
			},1000)
		}
	})
	}
	
}

//复制兑换码
$(".copy").on("click",function(){
	copyNum()
	$(".AreYouSure>span").fadeIn(function(){
		setTimeout(function(){
			$(".AreYouSure>span").fadeOut()
		},800)
	})
})
//复制完成点击“完成”
$(".AreYouSure>section>a").on("click",function(){
	$(".choose").find("i").html(parseInt($(".choose").find("i").html())-money)
	$(".AreYouSure>section").css("left","100%");
	$(".AreYouSure").css("display","none");
	$(".AreYouSure>div").css("display","block")
})
function copyNum() {
    var NumClip=$('.copyT').eq(0)[0];
    var NValue=NumClip.value;
    var valueLength = NValue.length;
    selectText(NumClip, 0, valueLength);
    document.execCommand("Copy","false",null);// 执行浏览器复制命令
    document.activeElement.blur()
    // alert("已复制,可分享给朋友啦，试试看。");
}
// input自带的select()方法在苹果端无法进行选择，所以需要自己去写一个类似的方法
function selectText(obj, startIndex, stopIndex) {
    if (obj.setSelectionRange) {
        obj.setSelectionRange(startIndex, stopIndex);
    } else if (obj.createTextRange) {
        var range = obj.createTextRange();
        range.collapse(true);
        range.moveStart('character', startIndex);
        range.moveEnd('character', stopIndex - startIndex);
        range.select();
    }
    obj.focus();
}

//去绑定
$(".bindPhone>div>p>span").eq(1).on("click",function(){
	$(".bindPhone").fadeOut()
});
$(".bindPhone>div>p>span").eq(0).on("click",function(){
	$(".bindPhone").fadeOut();
	// 跳转到手机绑定页面
});
$(".bindPhoneEmail>div>p>span").on("click",function(){
	$(".bindPhoneEmail").fadeOut()
});

var w_height=$(window).height();
$(window).on("resize",function(){
	if($(this).height()<w_height){
		$(".push").hide()
	}else{
		$(".push").show()
	}
})